package com.jy.modules.cims.component.common.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.data.common.dao.TCMmBailBondDao;
import com.jy.modules.cims.data.common.dao.TCMmCooperorgDealDao;
import com.jy.modules.cims.data.common.dao.TCMmDealCostDao;
import com.jy.modules.cims.data.common.dto.TCMmBailBondDTO;
import com.jy.modules.cims.data.common.dto.TCMmBailBondDealDetailDTO;
import com.jy.modules.cims.data.common.dto.TCMmCooperorgDealDTO;
import com.jy.modules.cims.data.common.dto.TCMmDealCostDTO;
import com.jy.modules.cims.data.dao.BailBondDao;
import com.jy.platform.core.common.BaseDTO;


/**
 * @classname: TCMmBailBondService
 * @description: 定义  担保金 实现类
 * @author:  dell
 */
@Service("com.jy.modules.cims.component.common.service.TCMmBailBondService")
public class TCMmBailBondService implements Serializable {

    private static final long serialVersionUID = 1L;
    
	@Autowired
	private TCMmBailBondDao dao;
	@Autowired
	private TCMmDealCostDao dealCostdao;
	@Autowired
	private TCMmCooperorgDealDao cooperorgDealDao;
	@Autowired
	private BailBondDao bailBondDao;
	
	
	
	/**
     * @author zhuwenbin
     * @description: 分页查询 担保金交易列表
     * @date 2015-02-05 15:32:51
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmBailBondDealDetailDTO> searchTCMmBailBondDealDetailByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmBailBondDealDetailDTO> dataList =  bailBondDao.searchBailBondDealDetailByPaging(searchParams);
		return dataList;
	}

	/**
     * @author dell
     * @description: 分页查询 担保金列表
     * @date 2015-02-05 15:32:51
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmBailBondDTO> searchTCMmBailBondByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmBailBondDTO> dataList =  dao.searchTCMmBailBondByPaging(searchParams);
		return dataList;
	}
	/**
     * @author dell
     * @description: 按条件查询担保金列表
     * @date 2015-02-05 15:32:51
     * @param searchParams 条件
     * @return
     * @throws
     */
	public List<TCMmBailBondDTO> searchTCMmBailBond(Map<String,Object> searchParams) throws Exception {
	    List<TCMmBailBondDTO> dataList = dao.searchTCMmBailBond(searchParams);
        return dataList;
    }
	/**
     * @author zhuwenbin
     * @description: 查询担保金交易对象
     * @date 2015-02-05 15:32:51
     * @param id
     * @return
     * @throws
     */ 
	public TCMmBailBondDealDetailDTO queryTCMmBailBondDealByPrimaryKey(String id) throws Exception {
		
		TCMmBailBondDealDetailDTO dto = bailBondDao.findTCMmBailBondDealByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmBailBondDealDetailDTO();
		
		return dto;
		
	}
	
	/**
     * @author dell
     * @description: 查询担保金对象
     * @date 2015-02-05 15:32:51
     * @param id
     * @return
     * @throws
     */ 
	public TCMmBailBondDTO queryTCMmBailBondByPrimaryKey(String id) throws Exception {
		
		TCMmBailBondDTO dto = dao.findTCMmBailBondByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmBailBondDTO();
		
		return dto;
		
	}

	/**
     * @title: insertTCMmBailBond
     * @author dell
     * @description: 新增 担保金对象
     * @date 2015-02-05 15:32:51
     * @param dto
     * @return
     * @throws
     */
	@SuppressWarnings("all")
	public Long insertTCMmBailBond(TCMmBailBondDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		int count = dao.insertTCMmBailBond(paramMap);
		
		TCMmBailBondDTO resultDto = (TCMmBailBondDTO) paramMap.get("dto");
		Long keyId = resultDto.getId();
		return keyId;
	}
	/**
     * @title: updateTCMmBailBond
     * @author dell
     * @description: 修改 担保金对象
     * @date 2015-02-05 15:32:51
     * @param paramMap
     * @return
     * @throws
     */
	public void updateTCMmBailBond(TCMmBailBondDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		dao.updateTCMmBailBond(paramMap);
	}
	/**
     * @title: deleteTCMmBailBondByPrimaryKey
     * @author dell
     * @description: 删除 担保金,按主键
     * @date 2015-02-05 15:32:51
     * @param paramMap
     * @throws
     */ 
	public void deleteTCMmBailBondByPrimaryKey(BaseDTO baseDto,String ids) throws Exception {
		if(StringUtils.isEmpty(ids)) throw new Exception("删除失败！传入的参数主键为null");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", baseDto);
		paramMap.put("ids", ids);
		dao.deleteTCMmBailBondByPrimaryKey(paramMap);
	}
	
	
	/**
     * @title: insertBailBondAdOrgdeal
     * @author zhuwenbin
     * @description: 担保金添加交易结算表以及合作机构交易表
     * @date 2015-02-04 10:55:25
     * @param dealCostDto，orgdealDto
     * @throws
     */ 
	public void insertBailBondAdOrgdeal(TCMmDealCostDTO dealCostDto,TCMmCooperorgDealDTO orgdealDto,TCMmBailBondDTO bailBondDto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dealCostDto);
		dealCostdao.insertTCMmDealCost(paramMap);
		paramMap.put("dto", orgdealDto);
		cooperorgDealDao.insertTCMmCooperorgDeal(paramMap);
		paramMap.put("dto", bailBondDto);
		dao.insertTCMmBailBond(paramMap);
	}

}

